package dieci.managers.stockmanager;

import dieci.database.product.ProductHibernateDAO;
import dieci.system.Product;
import java.util.List;

/**
 *
 * @author DuckSys
 */
public class ProductManager
{

    public ProductManager()
    {
        this.productDAO = new ProductHibernateDAO();
    }

    public void saveProduct(Product product)
    {
        //call prod dao to save the product in db
        productDAO.saveOrUpdate(product);        
    }

    public void saveProductList(List<Product> products)
    {
        //call prod dao to save the product list in db
        productDAO.saveOrUpdateList(products);        
    }
    
    public void deleteProduct(Product product)
    {
        productDAO.delete(product);
    }

    public Product find(String productCode)
    {
        return productDAO.findByProductCode(productCode);
    }
    
    public List<Product> findByName(String name)
    {
        if(name.isEmpty())
        {
            return productDAO.list();
        }
        return productDAO.findByProductName(name);
    }
    
    public Product findById(long id)
    {
        return productDAO.findById(id);
    }
    
    public List<Product> list()
    {
        return productDAO.list();
    }
    
    
    private ProductHibernateDAO productDAO;
}
